home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 07 - 1991 / 07.06 Jun 91 / Split Button Code / Split Button Code.text next >
Encoding:
Text File  |  1990-10-17  |  4.6 KB  |  180 lines  |  [TEXT/MSWD]

  1. LISTING #1 - makePolyButton script
  2. --message makePolyButton
  3. --syntax: makePolyButton(inMessage,outMessage)
  4. ----------inMessage is message to be called by 
  5. -----------------clicks within the polyButton
  6. ----------outMessage is message to be called by 
  7. -----------------clicks outside the polyButton
  8.  
  9. on makePolyButton inMessage,outMessage
  10.     put empty into pointList
  11.     choose line tool
  12.     set the cursor to cross
  13.     wait until the mouseClick
  14.     put the clickLoc into pointList
  15.  
  16.     repeat
  17.         wait until the mouseClick
  18.         put return & the clickLoc after pointList
  19.         put the number of lines of pointList¬
  20.         into count
  21.         drag from (line count-1 of pointList)¬
  22.         to (line count of pointList)
  23.         if abs(item 1 of last line of pointList¬
  24.         - item 1 of first line of pointList)<2¬
  25.         and abs(item 2 of last line of pointList¬
  26.         - item 2 of first line of pointList)<2¬
  27.         then exit repeat
  28.     end repeat
  29.  
  30.     put line 1 of pointList into¬
  31.     last line of pointList
  32.     put the number of card buttons into cbCount
  33.     set lockScreen to true
  34.     doMenu revert
  35.     choose button tool
  36.  
  37.     put item 1 of line 1 of pointList into maxV
  38.     put item 1 of line 2 of pointList into maxPenV
  39.     put item 1 of line 1 of pointList into minV
  40.     put item 1 of line 2 of pointList into minPenV
  41.  
  42.     put item 2 of line 1 of pointList into maxH
  43.     put item 2 of line 2 of pointList into maxPenH
  44.     put item 2 of line 1 of pointList into minH
  45.     put item 2 of line 2 of pointList into minPenH
  46.  
  47.     repeat with i=2 to count
  48.  
  49.         get item 1 of line i of pointList
  50.         if it > maxPenV then    --find the largest
  51.             if it > maxV then     --and second largest v
  52.                 put maxV into maxPenV
  53.                 put it into maxV
  54.             else
  55.                 put it into maxPenV
  56.             end if
  57.         end if
  58.  
  59.         if it < minPenV then     --find the smallest
  60.             if it < minV then    --and second smallest v
  61.                 put minV into minPenV
  62.                 put it into minV
  63.             else
  64.                 put it into minPenV
  65.             end if
  66.         end if
  67.  
  68.         get item 2 of line i of pointList
  69.         if it > maxPenH then    --find the largest
  70.             if it > maxH then    --and second largest h
  71.                 put maxH into maxPenH
  72.                 put it into maxH
  73.             else
  74.                 put it into maxPenH
  75.             end if
  76.         end if
  77.  
  78.         if it < minPenH then    --find the smallest
  79.             if it < minH then    --and second smallest h
  80.                 put minH into minPenH
  81.                 put it into minH
  82.             else
  83.                 put it into minPenH
  84.             end if
  85.         end if
  86.  
  87.     end repeat
  88.  
  89.     add 1 to cbCount    --create the interior button
  90.     doMenu "new button"
  91.     set the style of card button cbCount¬
  92.     to transparent
  93.     set the showName of card button cbCount¬
  94.     to false
  95.     set the autoHilite of card button cbCount¬
  96.     to false
  97.     set the rect of card button cbCount¬
  98.     to minPenV,minPenH,maxPenV,maxPenH
  99.     put "on mouseUp" into theScript
  100.     put return & inMessage after theScript
  101.     put return & "end mouseUp" after theScript
  102.     set the script of card button cbCount¬
  103.     to theScript
  104.  
  105.     repeat with i=1 to count-1
  106.         add 1 to cbCount    --create the edge buttons
  107.         set the cursor to busy
  108.         put line i of pointList into firstPoint
  109.         put line (i+1) of pointList into secondPoint
  110.         doMenu "new button"
  111.         set the name of card button cbCount¬
  112.         to "split" && i
  113.  
  114.         --determine the coördinates of the button:
  115.  
  116.         if (item 1 of firstPoint) < (item 1¬
  117.         of secondPoint) then
  118.             put item 1 of firstPoint into top
  119.             put item 1 of secondPoint into bottom
  120.         else
  121.             put item 1 of secondPoint into top
  122.             put item 1 of firstPoint into bottom
  123.         end if
  124.         if (item 2 of firstPoint) > (item 2¬
  125.         of secondPoint) then
  126.             put item 2 of firstPoint into right
  127.             put item 2 of secondPoint into left
  128.         else
  129.             put item 2 of secondPoint into right
  130.             put item 2 of firstPoint into left
  131.         end if
  132.  
  133.         set the rect of card button cbCount¬
  134.         to top,left,bottom,right
  135.         set the style of card button cbCount¬
  136.         to transparent
  137.         set the showName of card button cbCount¬
  138.         to false
  139.         set the autoHilite of card button cbCount¬
  140.         to false
  141.  
  142.         --determine the orientation of the
  143.         --"split" of the button:
  144.  
  145.         put "on mouseUp" into theScript
  146.  
  147.         if (item 1 of firstPoint) > (item 1¬
  148.         of secondPoint) then
  149.             if (item 2 of firstPoint) > (item 2¬
  150.             of secondPoint) then
  151.                 put return & "split " & quote & "\"¬
  152.                 & quote & "," & inMessage & "," &¬
  153.                 outMessage after theScript
  154.             else
  155.                 put return & "split " & quote & "/"¬
  156.                 & quote & "," & inMessage & "," &¬
  157.                 outMessage after theScript
  158.             end if
  159.         else
  160.             if (item 2 of firstPoint) > (item 2¬
  161.             of secondPoint) then
  162.                 put return & "split " & quote & "/"¬
  163.                 & quote & "," & outMessage & "," &¬
  164.                 inMessage after theScript
  165.             else
  166.                 put return & "split " & quote & "\"¬
  167.                 & quote & "," & outMessage & "," &¬
  168.                 inMessage after theScript
  169.             end if
  170.         end if
  171.  
  172.         put return & "end mouseUp" after theScript
  173.  
  174.         set the script of card button cbCount¬
  175.         to theScript
  176.     end repeat
  177.  
  178.     choose browse tool
  179. end makePolyButton
  180.